package cn.wonderland.feign.fallback;

import cn.wonderland.domain.User;
import cn.wonderland.feign.client.UserFeignClient;
import cn.wonderland.utils.JSONResult;
import com.alibaba.fastjson.JSON;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class UserFeignClientFallBack implements FallbackFactory<UserFeignClient> {
    @Override
    public UserFeignClient create(Throwable throwable) {
        return id -> {
            JSONResult<User> result = JSONResult.<User>builder()
                    .message("用户服务熔断！")
                    .code(100052)
                    .success(false)
                    .data(null)
                    .build();
            return result;
        };
    }
}
